document.addEventListener('click', async (e) => {
	
  const btn = e.target.closest('.view-detail-btn');
  if (!btn) return;

  const knowledgeId = btn.dataset.id;

  try {
    const res = await axios.get(`http://localhost:8080/api/knowledge/${knowledgeId}`);
    const knowledge = res.data.data;

    // 显示页面
    pages.forEach(p => p.classList.add('hidden'));
    document.getElementById('knowledge-detail-page').classList.remove('hidden');
    pageTitle.textContent = knowledge.title;

    // 设置数据
    document.getElementById('detail-title').textContent = knowledge.title;
    document.getElementById('detail-title').dataset.id = knowledge.id; // 记录 id 用于后续编辑
    document.querySelector('#knowledge-detail-page .fa-folder-o').parentElement.textContent = knowledge.categoryName;
    document.querySelector('#knowledge-detail-page .prose').innerHTML = `<p>${knowledge.content}</p>`;

  } catch (err) {
    console.error('加载失败:', err);
    alert('获取详情失败');
  }
});
